package com.heima.kafka.sample;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.Properties;

public class ProducerQuickStart2 {
    public static void main(String[] args) {
        Properties properties = new Properties();

        //kafka地址
        properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"192.168.200.130:9092");
        properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());

        //创建kafka生产者对象
        KafkaProducer<String, String> producer
                = new KafkaProducer<String, String>(properties);

        //投递消息
        ProducerRecord<String, String> producerRecord
                = new ProducerRecord<String, String>("itcast","hello world");

        producer.send(producerRecord);

        producer.close();
    }
}
